package com.youku.component.procedure;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.youku.component.result.ExecuteResult;

public abstract class SQLExecutor {

	protected Connection connection;

	protected String sql;

	public void setSql(String sql) {
		this.sql = sql;
	}

	public ExecuteResult execute(Connection connection) {
		this.connection = connection;
		return execute();
	}

	public PreparedStatement prepareStatement() {
		try {
			return connection.prepareStatement(sql);
		} catch (SQLException e) {
			throw new RuntimeException(e);
		}
	}

	protected abstract ExecuteResult execute();

}
